const API = require('../../../utils/api')
const {showToast} = require('../../../utils/util')
const app = getApp()

Page({

    /**
     * 页面的初始数据
     */
    data: {
        parkId: '',
        cardId: '',
        statistics:'',
        modeIndex: null
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        console.log(options)
        // this.setData({
        //     active: wx.getStorageSync('business_manage') ? 0 : 1,
        //     type: options.type,
        //     companyId: options.id,
        //     cardId: options.cardId,
        //     companyName: options.companyName
        // })
        this.setData({
            parkId: options.id,
            cardId: options.cardId,
        })
        this.get_back_park_sum()
        
        this.setData({ 
            modeIndex: wx.getStorageSync('garden-guidance') ? null : 1
         })
    },

    modeEvent() {
        let modeIndex = this.data.modeIndex += 1
        if (modeIndex > 3) {
            modeIndex = null;
            wx.setStorageSync('garden-guidance', true)
        }
        this.setData({ modeIndex })
    },
    navigator(event){
        console.log(event)
        const url = event.currentTarget.dataset.url
        const {parkId, cardId} = this.data
        if (!url) return showToast('开发中...')
        const str = url.indexOf('?') == -1 ? '?' : '&'
        wx.navigateTo({
          url: `${url}${str}id=${parkId}&cardId=${cardId}`
        })
    },

    /**
     * 接口 - 数据统计
     */
    get_back_park_sum:function(){
        let that = this
        API.get_back_park_sum({
            gardenId: that.data.parkId
        }).then( res => {
            if( res.code == 200 ){
                that.setData({
                    statistics: res.data
                })
            }
        }) 
    },

    route:function(e){
        let index = parseInt(e.currentTarget.id)
        console.log( index )

        //特殊拦截
        if( index == 9 ){ //海报裂变
            wx.switchTab({
              url: '/pages/share/share',
            })
            return
        }

        let page = ''
        switch(index){
            case 1: //信息修改
                page = '/pages/mine/park-manage/info/edit'
                break
            case 2: //名片编辑
                page = '/pages/mine/park-manage/card/edit'
                break
            case 3: //房源维护
                page = '/pages/mine/park-manage/house/list'
                break
            case 4: //新闻发布
                page = '/pages/mine/park-manage/news/list'
                break
            case 5: //看房工单
                page = '/pages/mine/park-manage/work/list'
                break
            case 6: //裂变团队
                page = '/pages/mine/share/share'
                break
            case 7: //客户管理
                page = '/pages/mine/park-manage/customer/customer'
                break
            case 8: //金融服务
                page = '/pages/mine/park-manage/serve/serve'
                break
            case 10: //邀请入驻
                page = '/pages/park/company/edit/intro'
                break
            case 11: //营销活动
                page = '/pages/home/marketing/marketing'
                break
                
        }
        wx.navigateTo({
          url: page + '?id=' + this.data.parkId + '&cardId=' + this.data.cardId,
        })

    }
})